﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jargon.Resources;

namespace Jargon.Web.Controls
{
    /// <summary>
    /// Display static Jargon text on the page
    /// </summary>
    [DefaultProperty("JargonKey")]
    [ToolboxData("<{0}:JargonText runat=server></{0}:JargonText>")]
    public class JargonText : WebControl
    {
        /// <summary>
        /// Gets or sets the key of the text to display in Jargon
        /// </summary>
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string JargonKey
        {
            get
            {
                String s = (String)ViewState["JargonKey"];
                return ((s == null) ? String.Empty : s);
            }
            set
            {
                ViewState["JargonKey"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the lettercase to acquire the Jargon text
        /// </summary>
        public JargonLetterCase LetterCase
        {
            get
            {
                JargonLetterCase letterCase = JargonLetterCase.Standard;
                if (ViewState["LetterCase"] != null)
                {
                    letterCase = (JargonLetterCase)ViewState["LetterCase"];
                }
                return letterCase;
            }
            set
            {
                ViewState["LetterCase"] = value;
            }
        }

        protected override void RenderContents(HtmlTextWriter output)
        {
            output.Write(JargonTextReader.GetString(JargonKey, LetterCase));
        }
    }
}
